package com.mti;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ConditionAdapter extends BaseAdapter {
	List<Condition> listCondition;
	LayoutInflater inflater;
	
	public ConditionAdapter(Context context,List<Condition> listCondition) {
		inflater = LayoutInflater.from(context);
		this.listCondition = listCondition;
	}

	public int getCount() {
		return listCondition.size();
	}

	public Object getItem(int position) {
		return listCondition.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	// Buffer
	private class ViewHolder {
		ImageView icon_condition_row;
		TextView day_condition_row;
		TextView low_high_condition_row;
		TextView condition_condition_row;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		
		if(convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.forecast_condition_row, null);
			holder.icon_condition_row = (ImageView)convertView.findViewById(R.id.icon_condition_row);
			holder.day_condition_row = (TextView)convertView.findViewById(R.id.day_condition_row);
			holder.low_high_condition_row = (TextView)convertView.findViewById(R.id.low_high_condition_row);
			holder.condition_condition_row = (TextView)convertView.findViewById(R.id.condition_condition_row);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.icon_condition_row.setImageBitmap(listCondition.get(position).getIcon());
		holder.day_condition_row.setText(listCondition.get(position).getDay());
		holder.low_high_condition_row.setText("" + listCondition.get(position).getLow()+ " - " + listCondition.get(position).getHigh());
		holder.condition_condition_row.setText(listCondition.get(position).getCondition());
		
		return convertView;
	}

}
